package com.thiny.android.game.thunderbolt.ui;

import java.util.ArrayList;
import java.util.List;

import com.thiny.android.game.thunderbolt.R;
import com.thiny.android.game.thunderbolt.role.GamePlayer;
import com.thiny.android.game.thunderbolt.util.Constants;
import com.thiny.android.game.thunderbolt.util.Utils;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class ReportScoreActivity extends Activity implements OnClickListener {

	private EditText editText;
	private long mScore;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.report_layout);
		editText = (EditText) findViewById(R.id.edit_name);
		findViewById(R.id.cancel).setOnClickListener(this);
		findViewById(R.id.share).setOnClickListener(this);
		findViewById(R.id.ok).setOnClickListener(this);
		mScore = getIntent().getLongExtra(Constants.EXTRA_KEY_SCORE, 0);
		((TextView) findViewById(R.id.score_title)).setText(getString(
				R.string.score_title_str, mScore));
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.ok:
			List<GamePlayer> list = Utils.getList();
			if (list == null) {
				list = new ArrayList<GamePlayer>();
			}
			list.add(new GamePlayer(editText.getText().toString(), mScore));
			Utils.stayList(list);
			finish();
			break;
		case R.id.cancel:
			finish();
			break;
		case R.id.share:
			Utils.StartShareApp(this, mScore);
			break;

		}

	}

}
